package com.neuedu.system.service.impl;
import lombok.RequiredArgsConstructor;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.neuedu.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.neuedu.system.domain.SkillList;
import com.neuedu.system.mapper.PeasantSkillListMapper;
import com.neuedu.system.domain.PeasantSkillList;
import com.neuedu.system.service.IPeasantSkillListService;

/**
 * 农民技能Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-18
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PeasantSkillListServiceImpl extends ServiceImpl<PeasantSkillListMapper, PeasantSkillList> implements IPeasantSkillListService
{
    private final PeasantSkillListMapper peasantSkillListMapper;

    /**
     * 查询农民技能
     *
     * @param id 农民技能主键
     * @return 农民技能
     */
    @Override
    public PeasantSkillList selectPeasantSkillListById(Long id)
    {
        return peasantSkillListMapper.selectPeasantSkillListById(id);
    }

    /**
     * 查询农民技能列表
     *
     * @param peasantSkillList 农民技能
     * @return 农民技能
     */
    @Override
    public List<PeasantSkillList> selectPeasantSkillListList(PeasantSkillList peasantSkillList)
    {
        return peasantSkillListMapper.selectPeasantSkillListList(peasantSkillList);
    }

    /**
     * 新增农民技能
     *
     * @param peasantSkillList 农民技能
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPeasantSkillList(PeasantSkillList peasantSkillList)
    {
        int rows = peasantSkillListMapper.insertPeasantSkillList(peasantSkillList);
        insertSkillList(peasantSkillList);
        return rows;
    }

    /**
     * 修改农民技能
     *
     * @param peasantSkillList 农民技能
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePeasantSkillList(PeasantSkillList peasantSkillList)
    {
        peasantSkillListMapper.deleteSkillListBySkillId(peasantSkillList.getId());
        insertSkillList(peasantSkillList);
        return peasantSkillListMapper.updatePeasantSkillList(peasantSkillList);
    }

    /**
     * 批量删除农民技能
     *
     * @param ids 需要删除的农民技能主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePeasantSkillListByIds(Long[] ids)
    {
        peasantSkillListMapper.deleteSkillListBySkillIds(ids);
        return peasantSkillListMapper.deletePeasantSkillListByIds(ids);
    }

    /**
     * 删除农民技能信息
     *
     * @param id 农民技能主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePeasantSkillListById(Long id)
    {
        peasantSkillListMapper.deleteSkillListBySkillId(id);
        return peasantSkillListMapper.deletePeasantSkillListById(id);
    }

    /**
     * 新增技能信息
     *
     * @param peasantSkillList 农民技能对象
     */
    public void insertSkillList(PeasantSkillList peasantSkillList)
    {
        List<SkillList> skillListList = peasantSkillList.getSkillListList();
        Long id = peasantSkillList.getId();
        if (StringUtils.isNotNull(skillListList))
        {
            List<SkillList> list = new ArrayList<SkillList>();
            for (SkillList skillList : skillListList)
            {
                skillList.setSkillId(id);
                list.add(skillList);
            }
            if (list.size() > 0)
            {
                peasantSkillListMapper.batchSkillList(list);
            }
        }
    }
}
